package com.fingersoft.feature.welcome;

import android.app.Activity;

import com.fingersoft.business.welcome.IWelcomeContext;
import com.fingersoft.feature.loading.LoadingContext;
import com.fingersoft.feature.login.LoginActivity;
import com.fingersoft.feature.personal.ui.PermissionsExplainActivity;
import com.fingersoft.im.utils.AppUtils;
import com.fingersoft.im.utils.JSONUtils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Type;

/**
 *
 * @author liubinbin
 * @date 2017/9/7
 */
public class SealWelcomeContext implements IWelcomeContext {
    @Override
    public void onClickEnter(Activity activity, boolean mIsFromMainActivity) {
        if (!mIsFromMainActivity) {
            LoginActivity.start(activity);
        }
        activity.finish();
    }
    @Override
    public void onPermissions_explain(Activity activity, boolean mIsFromMainActivity, boolean doPreConfig) {
        if (!mIsFromMainActivity) {
            PermissionsExplainActivity.start(activity,true, doPreConfig);
        }
        activity.finish();

    }
    @Override
    public String getApiUrl(@NotNull String path) {
        return AppUtils.getApiUrl(path, AppUtils.J_ECODE);
    }

    @Override
    public String getDid() {
        return AppUtils.getTokenInfo().getDid();
    }

    @Override
    public String getUserToken() {
        return AppUtils.getTokenInfo().getUserToken();
    }

    @Nullable
    @Override
    public String toJSONString(@NotNull Object userAgent) {
        return JSONUtils.toJsonString(userAgent);
    }

    @Override
    public Object fromJSONString(String json, Class clazz) {
        return JSONUtils.fromJsonString(json, clazz);
    }

    @Override
    public Object fromJSONString(String json, Type type) {
        return JSONUtils.fromJsonString(json, type);
    }

    @Override
    public int getWelcomeCount() {
        return AppUtils.getWelcomeCount();
    }

    @Override
    public boolean useLoadingView() {
        return AppUtils.useLoadingView();
    }

    @Override
    public void toLoading(Activity activity) {
        LoadingContext.instance.toLoading(activity);
    }
}
